#include "Graph.h"
#include <iostream>

Graph::Graph()
{
	//// add edges
	//GraphEdge ge1, ge2, ge3, ge4;
	//ge1.SetStartId(0);
	//ge1.SetEndId(1);

	//ge2.SetStartId(1);
	//ge2.SetEndId(2);

	//ge3.SetStartId(0);
	//ge3.SetEndId(3);

	//ge4.SetStartId(1);
	//ge4.SetEndId(4);

	////EdgeSet::iterator it = m_edgeSet.begin();
	////m_edgeSet.push_back(ge1);
	//m_edgeSet.push_back(ge1);
	//m_edgeSet.push_back(ge2);
	//m_edgeSet.push_back(ge3);
	//m_edgeSet.push_back(ge4);
	//

	//ge1.SetStartId(3);
	//ge1.SetEndId(5);

	//ge2.SetStartId(5);
	//ge2.SetEndId(6);


	//ge3.SetStartId(0);
	//ge3.SetEndId(7);

	//ge4.SetStartId(7);
	//ge4.SetEndId(6);

	//m_edgeSet.push_back(ge1);
	//m_edgeSet.push_back(ge2);
	//m_edgeSet.push_back(ge3);
	//m_edgeSet.push_back(ge4);

	//
	//ge1.SetStartId(4);
	//ge1.SetEndId(8);

	//ge2.SetStartId(8);
	//ge2.SetEndId(9);

	//ge3.SetStartId(3);
	//ge3.SetEndId(7);

	//m_edgeSet.push_back(ge1);
	//m_edgeSet.push_back(ge2);
	//m_edgeSet.push_back(ge3);

	//for (int i = 0; i != m_edgeSet.size(); i++)
	//{
	//	for (int j = 0; j != m_edgeSet.size(); j++)
	//	{
	//		if (m_edgeSet[i].GetStartId() == m_edgeSet[j].GetStartId())
	//		{
	//			m_nodes.push_back(m_edgeSet[i].GetStartId());
	//		}
	//	}
	//}

	//if (m_nodes.empty()) m_nodes.push_back(m_edgeSet[0].GetStartId());
	//for (int i = 0; i != m_edgeSet.size(); i++)
	//{
	//	for (int j = 0; j != m_nodes.size(); j++)
	//	{
	//		if (m_nodes[j].GetID() != m_edgeSet[i].GetStartId())
	//		{
	//			m_nodes.push_back(m_edgeSet[i].GetStartId());
	//			break;
	//		}
	//	}
	//}

	//for (int i = 0; i != 4; i++)
	//{
	//	m_nodes.push_back(i);
	//}
}

void Graph::AddNode(const GraphNode& node)
{
	//m_nodeMap[node.GetID()] = node;

	m_nodes.push_back(node);

}

GraphEdge& Graph::GetEdge(CellPosition start, CellPosition end)
{
	for (int i = 0; i != m_edges.size(); i++)
	{
		if (m_edges[i].GetStartId() == start && m_edges[i].GetEndId() == end)
		{
			return m_edges[i];
		}
	}
	// didn't find edge so return null edge
	return GraphEdge(CellPosition(), CellPosition(), 0.0f);
}

bool Graph::CheckEdge(CellPosition start, CellPosition end)
{
	for (int i = 0; i != m_edges.size(); i++)
	{
		if (m_edges[i].GetStartId() == start && m_edges[i].GetEndId() == end)
		{
			return true;
		}
	}

	return false;
}

//void Graph::RemoveNode(const GraphNode& node)
//{
//	//m_nodeMap.erase(m_nodeMap.find(node.GetID()));
//}
//
//void Graph::AddEdge(GraphEdge& edge)
//{
//	//m_nodeMap.find(edge.GetStartId());
//
//	//std::cout << edge.GetStartId() << std::endl;
//	
//	//m_edgeMap[edge.GetStartId()].push_back(edge);
//
//	//m_nodeMap[GraphNode(edge.GetStartId())].push_back(edge);
//
//	//for (int i = 0; i != m_nodes.size(); i++)
//	//{
//	//	if (m_nodes[i].GetID() == edge.GetEndId())
//	//	{
//	//		
//	//	}
//	//}
//
//	//m_edges.push_back(EdgeList());
//	//m_edges.back().push_back(edge);
//
//}

//GraphNode& Graph::GetNode(int id)
//{
//	return m_nodeMap[id];
//}
//
//const Edges& Graph::GetEdgeList(int id)
//{
//	return m_edgeMap[id];
//}

float Graph::CalcHeuristic(CellPosition start, CellPosition end)
{
	//CellPosition startPos = m_nodes[start].GetPos();
	//CellPosition endPos = m_nodes[end].GetPos();

	float x = 0, y = 0;
	x = (start.first * start.first + end.first * end.first);
	y = (start.second * start.second + end.second * end.second);
	return x + y;
}

void Graph::AddEdge(const GraphEdge& graphEdge)
{
	//m_edgeSet.push_back(graphEdge);
	m_edges.push_back(graphEdge);
}


Edges Graph::GetEdgeList(CellPosition startNode)
{
	Edges tempEdges;

	for (int i = 0; i != m_edges.size(); i++)
	{
		if (m_edges[i].GetStartId() == startNode)
		{
			tempEdges.push_back(m_edges[i]);
		}
	}

	return tempEdges;
}